#include "stdafx.h"
#include "IPopupMenu.h"


IPopupMenu::IPopupMenu()
{
	CMenu*menu=new CMenu;
	menu->CreatePopupMenu();
	imp = (DWORD_PTR)menu;
}

IPopupMenu::IPopupMenu( const IPopupMenu& )
{

}
#define menu ((CMenu*)imp)
IPopupMenu::~IPopupMenu()
{
	delete (CMenu*)imp;
}

IPopupMenu& IPopupMenu::appendString(UINT cmdid,const CString&text,  HICON hi /*= 0*/, bool bCheck /*= false*/)
{
	DWORD flags = MF_STRING;
	if(bCheck)flags |= MF_CHECKED;
	menu->AppendMenu(flags, cmdid, text);
	return *this;
}

IPopupMenu& IPopupMenu::appendSeparator()
{
	menu->AppendMenu(MF_SEPARATOR);
	return *this;
}

int IPopupMenu::run()
{
	CPoint pt;
	GetCursorPos(&pt);
	int cmd = menu->TrackPopupMenu(TPM_LEFTALIGN | TPM_NONOTIFY | TPM_RETURNCMD, pt.x, pt.y, AfxGetMainWnd());
	return cmd;
}

IPopupMenu& IPopupMenu::operator=( const IPopupMenu& )
{
	return *this;
}